 /*
  *  分页js  
  */  
var Page;  
  
(function(){  
      
//	<div class="page">
//	<a href="javascript:;">上一页</a>
//	<a href="javascript:;">1</a>
//	<a href="javascript:;">2</a>
//	<a href="javascript:;" class="active">3</a>
//	<a href="javascript:;">4</a>
//	<a href="javascript:;">5</a>
//	<a href="javascript:;">下一页</a>
//	
//	到第 <input type="text" name="" id="" value="" /> 页
//	<a href="javascript:;" class="gopage">确定</a>
//</div>
	
        var Page = {version:"1.0",author:"liuxingmi"};  
        var showPage = 9;  
        Page.navigation = function(divId, uri, method, pageSize, totalRecord, totalPage, currentPage, func){
            pageSize = parseInt(pageSize, 10);
            totalPage = parseInt(totalPage, 10);
            currentPage = parseInt(currentPage, 10);
            totalRecord = parseInt(totalRecord, 10);
        	$("#" + divId).html(""); 
           var nav = '';  
           if(currentPage == 1){  
               nav += '<a href="javascript:void(0);">上一页</a>';  
           } else {                      
               nav += '<a href="javascript:' + func + '(\''+ uri +'\',\''+ method + '\',' + pageSize + ',' + (parseInt(currentPage) -1) +');">上一页</a>';  
           }  
                     
          var start = currentPage - Math.floor(showPage/2);  
          var end = currentPage + Math.floor(showPage/2);  

          // if(end > totalPage){
          //    start -= (end - totalPage);
          // }

          if (start > totalPage - showPage) {
              start = totalPage - showPage;
          }
            if(start <= 0){
                start = 1;
            }
          if (end < showPage) {
              end = showPage;
          }
            if (end > totalPage) {
                end = totalPage;
            }
  
                       
         // if(currentPage < showPage && end > showPage){
         //    end = showPage;
         // }
         //
         // if(end > totalPage){
         //     end = totalPage;
         // }
                      
                       
         for(var i = start; i <= end; i++){
              var cls = i == currentPage ? 'active' : '';
              nav += '<a href="javascript:' + func + '(\''+ uri +'\',\''+ method + '\','+ pageSize + ',' + i + ');" class="' + cls + '">' + i + '</a>';
         }

         if(currentPage == totalPage){  
             nav += '<a href="javascript:void(0);">下一页</a>';  
         } else {  
             nav += '<a href="javascript:' + func + '(\''+ uri +'\',\''+ method + '\','+ pageSize + ',' + (parseInt(currentPage) + 1) +');" >下一页</a>';  
         }  
 
         nav += '到第 <input type="text" name="jumpPage" id="jumpPage"  /> 页'
                      + '<a href="javascript:Page.jump(' + func  +  ',\'' + uri +'\',\'' + method + '\',' + pageSize +',' + totalPage + ');" class="gopage">确定</a>' ;      
         $("#" + divId).html(nav);             
              
      };  
      
      Page.jump = function(func, uri, method, pageSize, totalPage){
    	  
    	  var num = $("#jumpPage").val();
    	  if(undefined == num || num == ""){
    		  alert("请输入页码");
    		  return ;
    	  }
    	  var regu =/^(\d)*?$/;
    	  var re = new RegExp(regu);
    	  if (re.test(num)) {
    		  if(num > totalPage){
    			  num = totalPage;
    		  }
    		  func(uri, method, pageSize, num);
    	  }else{
    		  alert("请输入数字");
    	      return false;
    	  }
    	  
      };    
     this.Page = Page;  
})();  